package com.dwms.controller;

import com.dwms.entity.CityAreaVO;
import com.dwms.entity.PageResponse;
import com.dwms.entity.QueryRequest;
import com.dwms.entity.Result;
import com.dwms.entity.system.city.area.request.CityAreaQueryRequest;
import com.dwms.entity.system.city.area.request.CityAreaRequest;
import com.dwms.entity.system.city.area.response.CityAreaResponse;
import com.dwms.feign.system.CityAreaFeignClient;

import com.dwms.utils.WebUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: CityAreaMapper
 * @Description: CityArea
 * @Create 2022/06/14 16:58
 * @Author WH
 * @Since 2.0.0
**/
@Tag(name = "城市地区管理")
@RestController(value = "CityAreaController")
@RequestMapping(value = "/system/cityArea")
@RequiredArgsConstructor
public class CityAreaController {

    private final HttpServletRequest request;
    private final CityAreaFeignClient cityAreaFeignClient;

    @Operation(summary = "新增城市地区")
    @PostMapping("/save")
    public Result save(@RequestBody CityAreaRequest cityAreaRequest) {
        WebUtil.getAdminRequest(request,cityAreaRequest);
        return cityAreaFeignClient.save(cityAreaRequest);
    }

    @Operation(summary = "修改城市地区")
    @PostMapping("/update")
    public Result update(@RequestBody CityAreaRequest cityAreaRequest) {
        WebUtil.getAdminRequest(request,cityAreaRequest);
        return cityAreaFeignClient.update(cityAreaRequest);
    }

    @Operation(summary = "分页查询城市地区")
    @PostMapping("/findPage")
    public Result<PageResponse<CityAreaResponse>> findPage(@RequestBody CityAreaQueryRequest query) {
        return cityAreaFeignClient.findPage(query);
    }

    @Operation(summary = "根据ID查询城市地区")
    @PostMapping("/findById")
    public Result findById(@RequestBody QueryRequest query){
        return cityAreaFeignClient.findById(query);
    }

    @Operation(summary = "删除城市地区")
    @PostMapping("/delete")
    public Result delete(@RequestBody QueryRequest query){
        return cityAreaFeignClient.delete(query);
    }

    @Operation(summary = "查找树形地区")
    @PostMapping("/findTree")
    public Result<List<CityAreaVO>> findTree() {
        return this.cityAreaFeignClient.findTree();
    }
}
